package com.story.rpc.dto;

import com.story.rpc.enums.ResponseCode;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
/**
 * 请求回复
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class RpcResp<T> implements Serializable {

    private String reqId;
    private Integer code;
    private String msg;
    private T data;

    public static <T> RpcResp<T> success(String reqId, T data) {
        RpcResp<T> rpcResp = RpcResp.<T>builder()
                .reqId(reqId)
                .code(ResponseCode.SUCCESS.getCode())
                .msg(ResponseCode.SUCCESS.getMsg())
                .data(data)
                .build();
        return rpcResp;
    }
    public static <T> RpcResp<T> fail(String reqId, T data) {
        RpcResp<T> rpcResp = RpcResp.<T>builder()
                .reqId(reqId)
                .code(ResponseCode.FAIL.getCode())
                .msg(ResponseCode.FAIL.getMsg())
                .data(data)
                .build();
        return rpcResp;
    }
}
